// job manage column
function format(value) {
  var value = value && value.substring(0, 10).replace(/-/gi, "/");
  return value ? new Date(value).Format("yyyy-MM-dd") : "--";
}
export function jobColumns() {
  const COLUMN_WIDTH = window.RPConfig.COLUMN_WIDTH
  return [
    {
      title: this.$t("module.job.jobCode"),
      key: "code",
      minWidth: 160,
      sortable: "custom",
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.code
            }
          },
          params.row.code
        );
      }
    },
    {
      title: this.$t("module.job.jobName"),
      key: "name",
      minWidth: 160,
      sortable: "custom",
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.name
            }
          },
          params.row.name
        );
      }
    },
    {
      title: this.$t("module.job.level"),
      key: "level",
      align: "left",
      minWidth: 100,
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.level
            }
          },
          params.row.level
        );
      }
    },
    {
      title: this.$t("module.job.effectBegin"),
      key: "startDate",
      align: "center",
      minWidth: COLUMN_WIDTH.COLUMN_WIDTH_YYYYMMDD,
      maxWidth: COLUMN_WIDTH.COLUMN_WIDTH_YYYYMMDD + COLUMN_WIDTH.MAX_WIDTH_MORE,

      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.startDate ? format(params.row.startDate) : ""
            }
          },
          params.row.startDate ? format(params.row.startDate) : ""
        );
      }
    },
    {
      title: this.$t("module.job.effectEnd"),
      key: "endDate",
      align: "center",
      minWidth: COLUMN_WIDTH.COLUMN_WIDTH_YYYYMMDD,
      maxWidth: COLUMN_WIDTH.COLUMN_WIDTH_YYYYMMDD + COLUMN_WIDTH.MAX_WIDTH_MORE,

      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.endDate ? format(params.row.endDate) : ""
            }
          },
          params.row.endDate ? format(params.row.endDate) : ""
        );
      }
    },
    {
      title: this.$t("common.status"),
      key: "enabled",
      align: "center",
      minWidth: 80,
      maxWidth: 80 + COLUMN_WIDTH.MAX_WIDTH_MORE,

      render: (h, params) => {
        return h(
          "StatusButton",
          {
            // 修改StatusButton内容居中
            style: {
              "justify-content": "center"
            },

            props: {
              status: params.row.enabled == 1 ? "0" : "1"
            }
          },
          params.row.enabled ? this.$t("common.enable") : this.$t("common.disable")
        );
      }
    },
    {
      title: this.$t("common.operating"),
      align: "left",
      fixed: "right",
      width: 55,
      render: (h, params) => {
        return h("RowTools", {
          props: {
            data: [
              {
                type: "icon",
                icon: "md-create",
                text: this.$t("common.edit"),
                handle: () => {
                  this.edit(params.row);
                }
              }
            ]
          }
        });
      }
    }
  ];
}
